<template>
	<div>
		<!-- 面包屑导航区 -->
		<el-breadcrumb separator-class="el-icon-arrow-right">
			<el-breadcrumb-item>首页</el-breadcrumb-item>
			<el-breadcrumb-item>订单管理</el-breadcrumb-item>
			<el-breadcrumb-item>订单列表</el-breadcrumb-item>
			<el-breadcrumb-item>订单添加</el-breadcrumb-item>
		</el-breadcrumb>
		<el-form :model="orderlist" ref="orderlist" label-width="100px" style="margin-top: 20px;width: 50%;margin-left: 20%;">
			<el-form-item label="用户编号" prop="user_id">
				<el-input v-model="orderlist.user_id"></el-input>
			</el-form-item>
			<el-form-item label="订单编号" prop="goods_id">
				<el-input v-model="orderlist.goods_id"></el-input>
			</el-form-item>
			<el-form-item label="订单状态" prop="order_status">
				<el-select v-model="orderlist.order_status" placeholder="请选择">
					<el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value">
					</el-option>
				</el-select>
			</el-form-item>
			<el-form-item style="float: right;">
				<el-button type="primary" @click="submit()">添加</el-button>
				<el-button @click="reset('orderlist')">重置</el-button>
				<el-button type="info" @click="goBack()">返回</el-button>
			</el-form-item>
		</el-form>
	</div>
</template>

<script>
import axios from "axios";
export default{
	name: "addorder",
	data(){
		return{
			 options: [{
			 	value: '进行中',
			 	label: '进行中'
			 }, {
			 	value: '已完成',
			 	label: '已完成'
			 }, {
			 	value: '异常',
			 	label: '异常'
			 }],
			 orderlist: {},
		}
	},
	methods:{
		submit(){
			let date = new Date();
			let time = date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate() + " " + date.toLocaleTimeString();
			this.orderlist.order_time = time;
			axios.post("http://localhost:8080/order/add?user_id="+this.orderlist.user_id+"&goods_id="+this.orderlist.goods_id+"&order_status="+this.orderlist.order_status+"&order_time="+this.orderlist.order_time)
			.then(res=>{
				console.log(res.data);
				this.$message('新增订单成功！');
				history.back();
			},err=>{
				console.log(err);
			})
		},
		reset(formName){
			this.$refs[formName].resetFields();
		},
		goBack(){
			history.back();
		}
	}
}
</script>

<style>
</style>
